Expand description
§alga-derive
Custom derive for alga
traits.
Supported traits:
AbstractQuasigroup
AbstractMonoid
AbstractSemigroup
AbstractGroup
AbstractGroupAbelian
AbstractRing
AbstractRingCommutative
AbstractField
§Examples
extern crate alga;
#[macro_use]
extern crate alga_derive;
use alga::general::Additive;
#[derive(Alga)]
#[alga_traits(Group(Additive))]
struct Struct;
This derive implements AbstractGroup
marker trait with Additive
operator and all
marker traits required by the algebraic groupness property
(AbstractMonoid
, AbstractSemigroup
, AbstractLoop
and AbstractQuasigroup
) for the target of the derive.
Traits required by these marker traits (Identity
, PartialEq
, TwoSidedInverse
and AbstractMagma
) should be implemented manually.
If #[alga_quickcheck]
attribute is added for the target of the derive,
then quickcheck
tests will be generated.
These tests will check that the algebraic properties of the derived trait are true for the type.
This attribute requires quickcheck
s Arbitrary
trait to be implemented for the target of the derive.
extern crate alga;
#[macro_use]
extern crate alga_derive;
use alga::general::{Additive, AbstractGroup};
#[derive(Alga)]
#[alga_traits(Group(Additive), Where = "T: AbstractGroup")]
#[alga_quickcheck(check(i32), check(i64))]
struct Struct<T>;
When there is generic parameters on the target of the derive,
then all the concrete type parameters that the tests are generated for can be specified in
alga_quickcheck
attribute by listing them in check
s.
If bounds are required for the alga
traits to be implemented,
they can be listed by Where = "A: Bound1. B: Bound2"
.
Derive Macros§
- Implementation of the custom derive